package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.entity.AlertData;
import com.zzyl.service.AlertRuleService;
import com.zzyl.vo.AlertRuleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description AlertRuleController
 * @Author apeng
 * @Date 2024-11-04
 */
@RestController
@RequestMapping("/alert-rule")
@Api(tags = "报警规则")
public class AlertRuleController extends BaseController{

    @Autowired
    private AlertRuleService alertRuleService;

    @ApiOperation("新增报警规则")
    @PostMapping("/create")
    public ResponseResult createAlertRule(@RequestBody AlertData dto){

        return alertRuleService.createAlertRule(dto);

    }

    @ApiOperation("分页获取警告规则列表")
    @GetMapping("/get-page")
    public ResponseResult<PageResponse<AlertRuleVo>> getPage(
            @ApiParam(value = "页码")
            @RequestParam(name = "pageNum",defaultValue = "1",required = true) Integer pageNum,
            @ApiParam(value = "每页大小")
            @RequestParam(name = "pageSize",defaultValue = "10",required = true) Integer pageSize,
            @ApiParam(value = "规则名称")
            @RequestParam(name = "alertRuleName") String alertRuleName,
            @ApiParam(value = "功能名称")
            @RequestParam(name = "functionName") String functionName,
            @ApiParam(value = "产品ID")
            @RequestParam(name = "productKey") String productKey) {

        return alertRuleService.getPage(pageNum,
                pageSize,alertRuleName,
                functionName,
                productKey);
    }

    @ApiOperation("获取单个告警规则")
    @GetMapping("/read/{id}")
    public ResponseResult<AlertRuleVo> readById(@PathVariable Long id){
        return alertRuleService.readById(id);
    }

    @ApiOperation("更新告警规则")
    @PutMapping("/update/{id}")
    public ResponseResult updateAlertRule(@PathVariable Long id,
                                          @RequestBody AlertRuleDto dto){
        return alertRuleService.updateAlertRule(id,dto);
    }


    @ApiOperation("删除告警规则")
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteAlertRule(@PathVariable Long id){
        return alertRuleService.deleteAlertRule(id);
    }

    @ApiOperation("启用-禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult startOrStop(@PathVariable Long id ,Long status){
        return alertRuleService.startOrStop(id,status);
    }

}
